// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   dealwith_recommend_ok.java

package logistics.discussion;

import include.nseer_cookie.*;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;
import validata.ValidataTag;

public class dealwith_recommend_ok extends HttpServlet
{

	public dealwith_recommend_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		javax.servlet.ServletContext dbApplication = dbSession.getServletContext();
		try
		{
			String time1 = "";
			Date now1 = new Date();
			SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			time1 = formatter1.format(now1);
			HttpSession session = request.getSession();
			nseer_db_backup1 design_db = new nseer_db_backup1(dbApplication);
			nseer_db_backup1 logistics_db = new nseer_db_backup1(dbApplication);
			if (logistics_db.conn((String)dbSession.getAttribute("unit_db_name")) && design_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				ValidataTag vt = new ValidataTag();
				String time = "";
				Date now = new Date();
				SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
				time = formatter.format(now);
				String product_logistics_recommend_ID = "";
				String discussion_ID = request.getParameter("discussion_ID");
				String processer_ID = request.getParameter("processer_ID");
				String processer = exchange.unURL(request.getParameter("processer"));
				String product_ID = request.getParameter("product_ID");
				String provider_ID = request.getParameter("provider_ID");
				Data dt = new Data((String)dbSession.getAttribute("unit_db_name"), "design_file", "product_ID", product_ID);
				Data dt1 = new Data((String)dbSession.getAttribute("unit_db_name"), "logistics_file", "provider_ID", provider_ID);
				String product_name = dt.getPara("product_name");
				String chain_id = dt.getPara("chain_id");
				String chain_name = dt.getPara("chain_name");
				String register_time = time1;
				String recommender = processer;
				String register = processer;
				String recommend_describe = "";
				String provider_name = dt1.getPara("provider_name");
				String provider_class = dt1.getPara("provider_class");
				String provider_web = dt1.getPara("provider_web");
				String provider_tel1 = dt1.getPara("provider_tel1");
				String type = dt1.getPara("type");
				String contact_person1 = dt1.getPara("contact_person1");
				if (vt.validata((String)dbSession.getAttribute("unit_db_name"), "design_file", "product_ID", product_ID, "recommend_logistics_tag").equals("0"))
				{
					try
					{
						product_logistics_recommend_ID = NseerId.getId("logistics/product_providers", (String)dbSession.getAttribute("unit_db_name"));
						String sql3 = (new StringBuilder("update design_file set recommend_logistics_tag='1' where product_ID='")).append(product_ID).append("'").toString();
						design_db.executeUpdate(sql3);
						String sql = (new StringBuilder("insert into logistics_product_providers_recommend(product_logistics_recommend_ID,chain_id,chain_name,product_ID,product_name,recommend_describe,register_time,recommender,register,check_tag,excel_tag) values ('")).append(product_logistics_recommend_ID).append("','").append(chain_id).append("','").append(chain_name).append("','").append(product_ID).append("','").append(product_name).append("','").append(recommend_describe).append("','").append(register_time).append("','").append(recommender).append("','").append(register).append("','0','2')").toString();
						logistics_db.executeUpdate(sql);
						String sql1 = (new StringBuilder("insert into logistics_product_providers_recommend_details(product_logistics_recommend_ID,details_number,provider_ID,provider_name,provider_class,provider_tel,provider_web,type,contact_person) values ('")).append(product_logistics_recommend_ID).append("','1','").append(provider_ID).append("','").append(provider_name).append("','").append(provider_class).append("','").append(provider_tel1).append("','").append(provider_web).append("','").append(type).append("','").append(contact_person1).append("')").toString();
						logistics_db.executeUpdate(sql1);
						sql1 = (new StringBuilder("update logistics_discussion_details set dealwith_tag='1' where discussion_ID='")).append(discussion_ID).append("' and product_ID='").append(product_ID).append("'").toString();
						logistics_db.executeUpdate(sql1);
						List rsList = new ArrayList();
						String elem[] = new String[3];
						sql = "select id,describe1,describe2 from logistics_config_workflow where type_id='03'";
						for (ResultSet rset = logistics_db.executeQuery(sql); rset.next(); rsList.add(elem))
						{
							elem = new String[3];
							elem[0] = rset.getString("id");
							elem[1] = rset.getString("describe1");
							elem[2] = rset.getString("describe2");
						}

						if (rsList.size() == 0)
						{
							sql = (new StringBuilder("update logistics_product_providers_recommend set check_tag='1' where product_logistics_recommend_ID='")).append(product_logistics_recommend_ID).append("'").toString();
							logistics_db.executeUpdate(sql);
							String provider_group = "";
							sql1 = (new StringBuilder("select * from logistics_file where provider_ID='")).append(provider_ID).append("'").toString();
							ResultSet rs1 = logistics_db.executeQuery(sql1);
							if (rs1.next())
							{
								String recommend_products = rs1.getString("recommend_products");
								if (rs1.getString("recommend_products").indexOf(product_name) == -1)
									recommend_products = (new StringBuilder(String.valueOf(recommend_products))).append(product_name).append(", ").toString();
								String sql2 = (new StringBuilder("update logistics_file set recommend_products='")).append(recommend_products).append("' where provider_ID='").append(provider_ID).append("'").toString();
								logistics_db.executeUpdate(sql2);
							}
							provider_group = (new StringBuilder(String.valueOf(provider_group))).append(provider_name).append(", ").toString();
							sql3 = (new StringBuilder("select * from design_file where product_ID='")).append(product_ID).append("'").toString();
							ResultSet rs3 = logistics_db.executeQuery(sql3);
							if (rs3.next())
							{
								String sql4 = (new StringBuilder("update design_file set provider_group='")).append(provider_group).append("' where product_ID='").append(product_ID).append("'").toString();
								logistics_db.executeUpdate(sql4);
							}
						} else
						{
							for (Iterator ite = rsList.iterator(); ite.hasNext(); logistics_db.executeUpdate(sql))
							{
								elem = (String[])ite.next();
								sql = (new StringBuilder("insert into logistics_workflow(config_id,object_ID,describe1,describe2) values ('")).append(elem[0]).append("','").append(product_logistics_recommend_ID).append("','").append(elem[1]).append("','").append(elem[2]).append("')").toString();
							}

						}
					}
					catch (Exception ex)
					{
						ex.printStackTrace();
					}
					response.sendRedirect((new StringBuilder("logistics/discussion/dealwith.jsp?discussion_ID=")).append(discussion_ID).toString());
				} else
				{
					String sqq = (new StringBuilder("select * from logistics_product_providers_recommend where product_ID='")).append(product_ID).append("' and (check_tag='1' or check_tag='0')").toString();
					ResultSet rs = logistics_db.executeQuery(sqq);
					if (rs.next())
					{
						product_logistics_recommend_ID = rs.getString("product_logistics_recommend_ID");
						sqq = (new StringBuilder("select * from logistics_product_providers_recommend_details where product_logistics_recommend_ID='")).append(rs.getString("product_logistics_recommend_ID")).append("' and provider_ID='").append(provider_ID).append("'").toString();
						rs = logistics_db.executeQuery(sqq);
						if (rs.next())
						{
							String sql1 = (new StringBuilder("update logistics_discussion_details set dealwith_tag='1' where discussion_ID='")).append(discussion_ID).append("' and product_ID='").append(product_ID).append("'").toString();
							logistics_db.executeUpdate(sql1);
						} else
						{
							sqq = (new StringBuilder("select * from logistics_product_providers_recommend_details where product_logistics_recommend_ID='")).append(product_logistics_recommend_ID).append("' order by details_number desc").toString();
							rs = logistics_db.executeQuery(sqq);
							if (rs.next())
							{
								int details_number = rs.getInt("details_number") + 1;
								String sql1 = (new StringBuilder("insert into logistics_product_providers_recommend_details(product_logistics_recommend_ID,details_number,provider_ID,provider_name,provider_class,provider_tel,provider_web,type,contact_person) values ('")).append(product_logistics_recommend_ID).append("','").append(details_number).append("','").append(provider_ID).append("','").append(provider_name).append("','").append(provider_class).append("','").append(provider_tel1).append("','").append(provider_web).append("','").append(type).append("','").append(contact_person1).append("')").toString();
								logistics_db.executeUpdate(sql1);
								sql1 = (new StringBuilder("update logistics_discussion_details set dealwith_tag='1' where discussion_ID='")).append(discussion_ID).append("' and product_ID='").append(product_ID).append("'").toString();
								logistics_db.executeUpdate(sql1);
							}
						}
						sqq = (new StringBuilder("update logistics_product_providers_recommend set change_time='")).append(time).append("',changer='").append(processer).append("',recommender='").append(recommender).append("',change_tag='1' where product_logistics_recommend_ID='").append(product_logistics_recommend_ID).append("'").toString();
						logistics_db.executeUpdate(sqq);
					}
					String sql3 = (new StringBuilder("update design_file set recommend_logistics_tag='1' where product_ID='")).append(product_ID).append("'").toString();
					design_db.executeUpdate(sql3);
					List rsList = GetWorkflow.getList(design_db, "logistics_config_workflow", "03");
					String elem[] = new String[3];
					if (rsList.size() == 0)
					{
						String sql = (new StringBuilder("update logistics_product_providers_recommend set check_tag='1' where product_logistics_recommend_ID='")).append(product_logistics_recommend_ID).append("'").toString();
						logistics_db.executeUpdate(sql);
						String provider_group = "";
						String sql1 = (new StringBuilder("select * from logistics_file where provider_ID='")).append(provider_ID).append("'").toString();
						ResultSet rs1 = logistics_db.executeQuery(sql1);
						if (rs1.next())
						{
							String recommend_products = rs1.getString("recommend_products");
							if (rs1.getString("recommend_products").indexOf(product_name) == -1)
								recommend_products = (new StringBuilder(String.valueOf(recommend_products))).append(product_name).append(", ").toString();
							String sql2 = (new StringBuilder("update logistics_file set recommend_products='")).append(recommend_products).append("' where provider_ID='").append(provider_ID).append("'").toString();
							logistics_db.executeUpdate(sql2);
						}
						provider_group = (new StringBuilder(String.valueOf(provider_group))).append(provider_name).append(", ").toString();
						sql3 = (new StringBuilder("select * from design_file where product_ID='")).append(product_ID).append("'").toString();
						ResultSet rs3 = logistics_db.executeQuery(sql3);
						if (rs3.next())
						{
							String sql4 = (new StringBuilder("update design_file set provider_group='")).append(provider_group).append("' where product_ID='").append(product_ID).append("'").toString();
							logistics_db.executeUpdate(sql4);
						}
					} else
					{
						String sql = (new StringBuilder("delete from logistics_workflow where object_ID='")).append(product_logistics_recommend_ID).append("'").toString();
						logistics_db.executeUpdate(sql);
						sql = (new StringBuilder("update logistics_product_providers_recommend set check_tag='0' where product_logistics_recommend_ID='")).append(product_logistics_recommend_ID).append("'").toString();
						logistics_db.executeUpdate(sql);
						for (Iterator ite = rsList.iterator(); ite.hasNext(); logistics_db.executeUpdate(sql))
						{
							elem = (String[])ite.next();
							sql = (new StringBuilder("insert into logistics_workflow(config_id,object_ID,describe1,describe2) values ('")).append(elem[0]).append("','").append(product_logistics_recommend_ID).append("','").append(elem[1]).append("','").append(elem[2]).append("')").toString();
						}

					}
					response.sendRedirect((new StringBuilder("logistics/discussion/dealwith.jsp?discussion_ID=")).append(discussion_ID).toString());
				}
				logistics_db.commit();
				design_db.commit();
				logistics_db.close();
				design_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
